<?php
namespace app\index\controller;
use think\view;
use think\Db;
use think\Session;
use Qiniu\Auth as Auth;
use think\Cache;
use traits\model\SoftDelete;

class Developer extends CommonController
{
    //技术管理
    public function index()
    {

        return $this->fetch();
    }
    /**
     * 技术待审核列表
     */
    public  function check(){
        return $this->fetch();
    }
    /**
     * 待审核技术列表
     */
    public function get_check(){
        # 接收layui发送的limit
        if (trim($_GET['limit'])) {
            $limit = trim($_GET['limit']);
        }else{
            $limit = 15;
        }
        $pageSize = $limit;
        $page = $_GET['page'];

        $list = DB::name('developer')
            ->where(array(
                'state'=>1   //待审核技术
            ))
            ->order('uptime desc')
            ->page($page,$pageSize)
            ->select();
        for($i=0;$i<count($list);$i++){
            preg_match_all('/[\x{4e00}-\x{9fff}]+/u', $list[$i]['tip'], $matches);//只要汉字
            $str = join('', $matches[0]);
            $list[$i]['tip']  =$str;
        }

        if($list){
            $data['code'] = '0';
            $data['msg'] = '';
            $data['count'] = count($list);
            $data['data'] = $list;
        }else{
            $data['code'] = '0';
            $data['msg'] = '暂无数据';
            $data['count'] = 0;
            $data['data'] = '';
        }

        exit(json_encode($data));


    }
    /**
     * 删除待审核技术
     */
    public function check_del(){
       if($_POST){
           $_POST['state'] = '已取消';

           $res = Db::name('developer')->update($_POST);
           if($res){

               return show(1,'删除成功');
           }else{
               return show(0,'删除失败，请重新删除');
           }
       }

    }

    /**
     * 审核技术
     */
    public function check_edit(){
        if($_GET){
            $map['id']  = $_GET['id'];
            $list = Db::name('developer')->where($map)->find();

            $this->assign('list',$list);
        }

        return $this->fetch();
    }

    /**
     * 处理待审核技术审核
     */
    public function up_check(){
        if($_POST){
            $res = DB::name('developer')->where(array(
                'id'=>$_POST['id'],
                'state'=>'1'
            ))->find();
            if($res){
               if($_POST['pass']==1){
                   $data['state'] = '2';
                   $data['id'] = $_POST['id'];
                   $res = Db::name('developer')->update($data);
                   if($res){

                       return show(1,'审核成功');
                   }else{
                       return show(0,'审核失败');
                   }
               }else{
                   $data['state'] = '0';
                   $data['id'] = $_POST['id'];
                   $res = Db::name('developer')->update($data);
                   if($res){

                       return show(1,'审核不通过成功');
                   }else{
                       return show(0,'审核不通过失败');
                   }
               }
            }else{
                return show(0,'该技术不存在，请确认信息后再试');
            }

        }
    }


    /**
     * 技术数据列表
     */
    public function get_developer(){
        # 接收layui发送的limit
        if (trim($_GET['limit'])) {
            $limit = trim($_GET['limit']);
        }else{
            $limit = 15;
        }
        $pageSize = $limit;
        $page = $_GET['page'];

        //搜索部分
        $searchParams = json_decode($_GET['searchParams'],true);
        $phone = $searchParams['phone'];
        $name = $searchParams['name'];
        $qq = $searchParams['qq'];
        $tags = $searchParams['tags'];

        if($phone){
            $list = DB::name('developer')
                ->whereOr('phone', 'like', '%' . $phone . '%')
                ->where('state',2)
                ->order('uptime desc')
                ->page($page,$pageSize)
                ->select();
        }
        if($name){
            $list = DB::name('developer')
                ->whereOr('name', 'like', '%' . $name . '%')
                ->where('state',2)
                ->order('uptime desc')
                ->page($page,$pageSize)
                ->select();
        }
        if($qq){
            $list = DB::name('developer')
                ->whereOr('qq', 'like', '%' . $qq . '%')
                ->where('state',2)
                ->order('uptime desc')
                ->page($page,$pageSize)
                ->select();
        }
        if($tags){
            $list = DB::name('developer')
                ->whereOr('tags', 'like', '%' . $tags . '%')
                ->where('state',2)
                ->order('uptime desc')
                ->page($page,$pageSize)
                ->select();
        }
        if(!$phone && !$name && !$qq && !$tags){
            $list = DB::name('developer')
                ->where('state',2)
                ->order('uptime desc')
                ->page($page,$pageSize)
                ->select();
        }


        if($list){
            $data['code'] = '0';
            $data['msg'] = '';
            $data['count'] = count($list);
            $data['data'] = $list;
        }else{
            $data['code'] = '0';
            $data['msg'] = '暂无数据';
            $data['count'] = 0;
            $data['data'] = '';
        }

        exit(json_encode($data));

    }


    /**
     * 查看技术详情
     */
    public function see(){
        if($_GET){
            $map['id']  = $_GET['id'];
            $list = Db::name('developer')->where($map)->find();
            $this->assign('list',$list);
        }
        return $this->fetch();
    }

    /**
     * 获取电话
     */

    public function get_phone(){
        # 接收layui发送的limit
        if (trim($_GET['limit'])) {
            $limit = trim($_GET['limit']);
        }else{
            $limit = 15;
        }
        $pageSize = $limit;
        $page = $_GET['page'];


            $list = DB::name('inphone')
                ->order('uptime desc')
                ->page($page,$pageSize)
                ->select();


        if($list){
            $data['code'] = '0';
            $data['msg'] = '';
            $data['count'] = count($list);
            $data['data'] = $list;
        }else{
            $data['code'] = '0';
            $data['msg'] = '暂无数据';
            $data['count'] = 0;
            $data['data'] = '';
        }

        exit(json_encode($data));
    }



    public function phone()
    {
        return $this->fetch();
    }

    public function yes_phone(){
        $map['id'] = $_POST['id'];
        $_POST['state'] = 2;
        $res = Db::name('inphone')->where($map)->update($_POST);;
        if($res){
            return show(1,'确认成功！');
        }else{
            return show(0,'确认失败！');
        }
    }

}
